package ar.uba.fi.posgrado.economy.web.action.account;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import ar.uba.fi.posgrado.academy.model.Teacher;
import ar.uba.fi.posgrado.academy.service.TeacherService;
import ar.uba.fi.posgrado.economy.model.Pay;
import ar.uba.fi.posgrado.economy.service.PayService;
import ar.uba.fi.posgrado.economy.web.form.provider.ProviderAccountForm;

/**
 * 
 * @author pablo.tortorella
 */
public class ShowProviderAccountDetailsAction extends Action {

	private PayService payService;

	private TeacherService teacherService;

	/**
	 * @return the teacherService
	 */
	public TeacherService getTeacherService() {
		return teacherService;
	}

	/**
	 * @param teacherService
	 *            the teacherService to set
	 */
	public void setTeacherService(TeacherService teacherService) {
		this.teacherService = teacherService;
	}

	@Override
	public ActionForward execute(ActionMapping mapping, ActionForm actionForm,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		ProviderAccountForm form = (ProviderAccountForm) actionForm;
		Long teacherId = form.getTeacherId();

		// busco el docente, lo coloco en el honorario para colocarlo en el pago
		Teacher teacher = teacherService.getById(teacherId);

		// busco los pagos realizados al docente
		List<Pay> teacherPays = payService.getPaysByTeacher(teacher);

		form.setAccountId(teacher.getAccount().getId());
		form.setTeacherId(teacher.getId());
		form.setTeacherName(teacher.getName());
		form.setPays(teacherPays);

		return mapping.findForward("success");
	}

	/**
	 * @param payService
	 *            the payService to set
	 */
	public void setPayService(PayService payService) {
		this.payService = payService;
	}

}
